/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package model;

import com.jme3.math.Quaternion;
import com.jme3.math.Vector3f;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;


/**
 *
 * @author Peter
 */
public class Ninja {
   private float direction;
   private Quaternion directionQ;
   private Vector3f location;
   private PropertyChangeSupport listeners;
   
   public Ninja(){
       this.listeners = new PropertyChangeSupport(this);
   }
   
   public void init(){
       this.location = new Vector3f(0.0f, -4.2f, -2.0f);
       setDirection(com.jme3.math.FastMath.PI);
       this.listeners.firePropertyChange("turn", null, this.directionQ);
       this.listeners.firePropertyChange("move", null, this.location);
   }
   
    public void turnLeft(float amount){
        setDirection(this.direction + amount);
        this.listeners.firePropertyChange("turn", null, this.directionQ);
    }
    
    public void turnRight(float amount){
        setDirection(this.direction - amount);
        this.listeners.firePropertyChange("turn", null, this.directionQ);
    }
    
    public void walkForward(float amount){
        this.location = this.location.subtract(this.directionQ.mult(Vector3f.UNIT_Z.mult(amount)));
        this.listeners.firePropertyChange("walk", null, this.location);
    }
    
    public void addListener(PropertyChangeListener listener) {
        this.listeners.addPropertyChangeListener(listener);
    }
    
    private void setDirection(float dir){
        this.direction = dir % com.jme3.math.FastMath.TWO_PI;;
        float[] a = {0,this.direction,0};
        this.directionQ = new Quaternion(a);
    }
    public float getDirection(){
        return this.direction;
    }

    public void backFlip() {
        this.listeners.firePropertyChange("backflip", null, null);
    }
}
